home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
ici
/
ici.cpi
/
unary.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-27
|
1KB
|
69 lines
#include "exec.h"
#include "float.h"
#include "int.h"
#include "op.h"
#include "parse.h"
#include "buf.h"
#include "null.h"
int
op_unary()
{
int_t *i;
float_t *f;
switch (opof(x_top[-1])->op_code)
{
case t_subtype(T_EXCLAM):
if (isfalse(o_top[-1]))
o_top[-1] = objof(o_one);
else
o_top[-1] = objof(o_zero);
--x_top;
return 0;
case t_subtype(T_TILDE):
if (!isint(o_top[-1]))
goto fail;
if ((i = new_int(~intof(o_top[-1])->i_value)) == NULL)
return 1;
o_top[-1] = objof(i);
loose(i);
--x_top;
return 0;
case t_subtype(T_MINUS):
if (isint(o_top[-1]))
{
if ((i = new_int(-intof(o_top[-1])->i_value)) == NULL)
return 1;
o_top[-1] = objof(i);
loose(i);
--x_top;
return 0;
}
else if (isfloat(o_top[-1]))
{
if ((f = new_float(-floatof(o_top[-1])->f_value)) == NULL)
return 1;
o_top[-1] = objof(f);
loose(f);
--x_top;
return 0;
}
fail:
default:
switch (opof(x_top[-1])->op_code)
{
case t_subtype(T_EXCLAM): error = "!"; break;
case t_subtype(T_TILDE): error = "~"; break;
case t_subtype(T_MINUS): error = "-"; break;
default: error = "<unknown unary operator>"; break;
}
sprintf(buf, "attempt to perform \"%s %s\"",
error, o_top[-1]->o_type->t_name);
error = buf;
return 1;
}
}